	//根据选择的套表
	function initTreePanels(ids){
		var xmlLbales = ['A','B','C','D','E','F','G','H','I','G','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
		var xmlIds = [];
		if(trim(ids)==''){
			//没传ids时直接返回
			return;
		}
		var ids = ids.split(',');
		for(var i = 0;i<ids.length;i++){
			xmlIds.push({key:xmlLbales[i],value:ids[i]});
			Ext.getCmp('treepanels').add({
				id: 'tree-panel'+i,
				title:'套表'+xmlLbales[i],
				xmlId:ids[i],
				xmlLabel:xmlLbales[i],
				tbar:['->','-',{
					text:'选择套表',
					iconCls: 'book',
					handler:function(){
						Ext.getCmp('winId').show();
					}
				}],
				items:[
{
	id: 'measure-tree'+i,
	xmlId:ids[i],
	xmlLabel:xmlLbales[i],
	region:'north',
	height:(all_height-50)/2,
	width:all_width * 20 / 100,
	autoScroll:true,
	split:true,
	collapsible: true,
	title: '指标字典',
	ddGroup: 'measureGridDD',
	enableDrag:true,
	xtype: 'treepanel',
	useArrows:true,
	rootVisible : false,
	root: {text: '指标字典',draggable: false,id: '-1',isRoot:true},
	loader: new Ext.tree.TreeLoader({ 
			xmlId:ids[i],
			treeId:'measure-tree'+i,
			dataUrl: '${pageContext.request.contextPath}/crossReport.report?decorate=no',
			listeners:{beforeload:function(treeLoader, node){
					if(node.attributes.isRoot==true){
						this.baseParams.method = "getRoot";
					}else{
						this.baseParams.method = "getChilds";
					}
					this.baseParams.treeId = this.treeId;
					this.baseParams.xmlId = this.xmlId;
					this.baseParams.tableName = node.attributes.table;
					this.baseParams.pid = node.attributes.val;
					this.baseParams.level = node.attributes.level;
					this.baseParams.dir = node.attributes.d;
					this.baseParams.time = node.attributes.time;
					this.baseParams.isMeasures = true;
					this.baseParams.currentTime = Ext.getCmp('currentTime').getRawValue();
					this.baseParams.currentTimeWeiBiao = Ext.getCmp('currentTimeWeiBiao').getValue();
		   }}
	}),
	listeners:{
		beforeappend:function(tree,parent,node){
 			//判断是否是报告期
			if(node.attributes.isTime=='true'){
				return false;	
			}else{
				return true;
			}
 		}
	}
},{
	id: 'dimension-tree'+i,
	height:(all_height-50)/2,
	width:all_width * 20 / 100,
	region:'center',
	autoScroll:true,
	split:true,
	title: '维度字典',
	ddGroup: 'dimensionGridDD',
	enableDrag:true,
	xtype: 'treepanel',
	useArrows:true,
	rootVisible : false,
	root: {text: '维度字典',draggable: false,id: '-1',isRoot:true},
	loader: new Ext.tree.TreeLoader({ 
			xmlId:ids[i],
			treeId:'dimension-tree'+i,
			dataUrl: '${pageContext.request.contextPath}/crossReport.report?decorate=no',
			listeners:{beforeload:function(treeLoader, node){
					if(node.attributes.isRoot==true){
						this.baseParams.method = "getRoot";
					}else{
						this.baseParams.method = "getChilds";
					}
					this.baseParams.treeId = this.treeId;
					this.baseParams.xmlId = this.xmlId;
					this.baseParams.tableName = node.attributes.table;
					this.baseParams.pid = node.attributes.val;
					this.baseParams.level = node.attributes.level;
					this.baseParams.dir = node.attributes.d;
					this.baseParams.time = node.attributes.time;
					this.baseParams.isDimensions = true;
					this.baseParams.currentTime = Ext.getCmp('currentTime').getRawValue();
					this.baseParams.currentTimeWeiBiao = Ext.getCmp('currentTimeWeiBiao').getValue();
		   }}
	}),
	listeners:{
		beforeappend:function(tree,parent,node){
 			//判断是否是报告期
			if(node.attributes.isTime=='true'){
				return false;	
			}else{
				return true;
			}
 		}
	}
}
				]});
		}
		xmlIds = Ext.encode(xmlIds);
		Ext.getCmp('treepanels').setActiveTab(0);
		return Ext.encode(xmlIds);
	}
	
	//预览
	function preview(){
		//var start = new Date().getTime();
    	//开启容器的等待提示
    	Ext.getCmp('pivotgridContainer').el.mask("正在加载数据，请稍候……");
		/*
		 * 填充查询的必要参数
		 */
		var store = Ext.getCmp('pivotgrid').store;
		//xmlId 套表id
		store.baseParams.xmlId = xml_id_;
		//事实表当前期
		store.baseParams.currentTime = Ext.getCmp('currentTime').getRawValue();
		//维表当前期
		store.baseParams.currentTimeWeiBiao = Ext.getCmp('currentTimeWeiBiao').getValue();
		//是否总计
		var isSum = Ext.getCmp('isSum').isSum;
		store.baseParams.isSum = isSum;
		//全局查询条件
		var conditions='';
		if(Ext.getCmp('conditions_grid_')){
			Ext.getCmp('conditions_grid_').getStore().each(function(record){
				conditions += ' ' + record.data.join + ' ' + record.data.code;
			});
		}
		store.baseParams.conditions = conditions;
		//指标信息和别名信息
		var collist=[]; //查询用指标信息
		var colLabels=[]; //指标别名数组
		var maxColLength = 0; //指标别名最大长度
		var colIndex = 0; //指标别名索引
		var measuredata = Ext.getCmp('measures_grid').getStore().each(
				function(record){
					collist.push(record.data.code);
					var label = (++colIndex < 10?('0' + colIndex):colIndex) + "." + record.data.name;
					colLabels.push(label);
					maxColLength = (getLen(label)*7 > maxColLength)?(getLen(label)*7):maxColLength;
				}
		);
		if(collist == ''){
			alert("指标不能为空");
			Ext.getCmp('pivotgridContainer').el.unmask();//关闭遮罩
			return;
		}
		store.baseParams.collist = Ext.encode(collist);
		store.baseParams.colLabels = Ext.encode(colLabels);
		//收集宾栏主栏里的维表信息 并同时收集reader 并同时收集leftAxis 和 topAxis 并同时收集交叉报表宽度和高度的信息
		var dimensionTables=[];
		var reader=[{name:'column',type: 'string'},{name:'value',type:'int'}];
		var leftAxis = [];
		var topAxis = [];
		var index = 0; //记录当前是第几个维表
		var dimensionLabels={}; //指标别名数组
		var dimensionIndex = 0; //指标别名索引
		var leftAxisWidth = 0; //leftAxis宽度
		var leftAxisCount = 1; //leftAxis总cell数
		var leftAxisHeight = 0; //leftAxis高度
		var leftHasZhibiao = false; //leftAxis是否有指标
		var topAxisWidth = 0; //topAxis宽度
		var topAxisCount = 1; //topAxis总cell数
		var topAxisHeight = 0; //topAxis高度
		var topHasZhibiao = false; //topAxis是否有指标
		var root = Ext.getCmp('binlan').root;
		root.eachChild(function(node){
			if(node.attributes.isDir){  //是一个分组
				var table = {}; //查询用
				var ids = []; // '1','2','3'
				var hasChild = false;
				var readertable = {}; //配置reader用
				readertable.type = 'string';
				var topAxistable = {}; //配置topAxis用
				var maxTopAxisWidth = 80; //自动计算并配置topAxis宽度
				dimensionIndex = 0; //别名索引置为0
				topAxisCount *= (node.childNodes.length+1); //计算top总cell数 +1为小计
				node.eachChild(function(node_){
					hasChild = true;
					table.dimension = node_.attributes.table;
					table.isTree = node_.attributes.tree;
					ids.push("'"+node_.attributes.val+"'");
					readertable.name="DIMENSION" + index;
					topAxistable.dataIndex = "DIMENSION" + index;
					var label = (++dimensionIndex < 10?('0' + dimensionIndex):dimensionIndex) + '.' + node_.attributes.group;
					maxTopAxisWidth = (getLen(label)*7 > maxTopAxisWidth)?(getLen(label)*7):maxTopAxisWidth;
					dimensionLabels[node_.attributes.table + '.' + node_.attributes.val] = label;
				});
				table.id = ids.join(",");
				if(hasChild){
					dimensionLabels[table.dimension + '.小计'] = (++dimensionIndex < 10?('0' + dimensionIndex):dimensionIndex) + '.' + '小计';
					dimensionTables.push(table);
					reader.push(readertable);
					topAxistable.width = maxTopAxisWidth;
					topAxis.push(topAxistable);
					index++;
				}
			}
			if(node.attributes.isZhiBiao){  //是一个指标分组
				topAxis.push({dataIndex:'column',width:maxColLength});
				topAxisCount *= colLabels.length; //计算topAxis总cell数
				topHasZhibiao = true; //leftAxis有指标
			}
			topAxisHeight += 22;//计算top总高度,每有一个分组高度增加一行高度
		});
		//计算topAxisWidth
		if(isSum){
			if(!topHasZhibiao){ //没有指标的情况多算一个总计cell
				topAxisCount++;
			}else if(topHasZhibiao && (topAxis.length != 1)){
				topAxisCount += colLabels.length;//有指标的情况有几个指标就多算几个总计cell
			}
		}
		topAxisWidth = topAxis[topAxis.length-1].width * topAxisCount;
		root = Ext.getCmp('zhulan').root;
		root.eachChild(function(node){
			if(node.attributes.isDir){  //是一个分组
				var table = {}; //查询用
				var ids = []; // '1','2','3'
				var hasChild = false;
				var readertable = {}; //配置reader用
				readertable.type = 'string';
				var leftAxistable = {}; //配置leftAxis用
				var maxLeftAxisWidth = 80; //自动计算并配置leftAxis宽度
				dimensionIndex = 0; //别名索引置为0
				leftAxisCount *= (node.childNodes.length+1); //计算leftAxis总cell数 +1为小计
				node.eachChild(function(node_){
					hasChild = true;
					table.dimension = node_.attributes.table;
					table.isTree = node_.attributes.tree;
					ids.push("'"+node_.attributes.val+"'");
					readertable.name="DIMENSION" + index;
					leftAxistable.dataIndex = "DIMENSION" + index;
					var label = (++dimensionIndex < 10?('0' + dimensionIndex):dimensionIndex) + '.' + node_.attributes.group;
					maxLeftAxisWidth = (getLen(label)*7 > maxLeftAxisWidth)?(getLen(label)*7):maxLeftAxisWidth;
					dimensionLabels[node_.attributes.table + '.' + node_.attributes.val] = label;
				});
				table.id = ids.join(",");
				if(hasChild){
					dimensionLabels[table.dimension + '.小计'] = (++dimensionIndex < 10?('0' + dimensionIndex):dimensionIndex) + '.' + '小计';
					dimensionTables.push(table);
					reader.push(readertable);
					leftAxistable.width = maxLeftAxisWidth;
					leftAxisWidth += maxLeftAxisWidth; //最长字符串宽度计算入leftAxis宽度
					leftAxis.push(leftAxistable);
					index++;
				}
			}
			if(node.attributes.isZhiBiao){  //是一个指标分组
				leftAxis.push({dataIndex:'column',width:maxColLength});
				leftAxisWidth += maxColLength; //最长字符串宽度计算入leftAxis宽度
				leftAxisCount *= colLabels.length;  //计算leftAxis总cell数
				leftHasZhibiao = true; //leftAxis有指标
			}
		});
		//计算leftAxisHeight
		if(isSum){
			if(!leftHasZhibiao){ //没有指标的情况多算一个总计cell
				leftAxisCount++;
			}else if(leftHasZhibiao && (leftAxis.length != 1)){
				leftAxisCount += colLabels.length;//有指标的情况有几个指标就多算几个总计cell
			}
		}
		leftAxisHeight = leftAxisCount*21;
		store.baseParams.dimensionTables = Ext.encode(dimensionTables);
		store.baseParams.dimensionLabels = Ext.encode(dimensionLabels);
		//设置报表长度和宽度
		pivotGrid.setWidth(topAxisWidth + leftAxisWidth);
		pivotGrid.setHeight(topAxisHeight + leftAxisHeight);
		//自动生成交叉报表配置
		pivotGrid.leftAxis.setDimensions(leftAxis);
		pivotGrid.topAxis.setDimensions(topAxis);
		//重配reader
		store.reader = new Ext.data.JsonReader({idProperty: 'id'},Ext.data.Record.create(reader));
		store.recordType = store.reader.recordType;
		Ext.getCmp('pivotgrid').store.fields = store.recordType.prototype.fields;
		//重新加载数据
		Ext.getCmp('pivotgrid').store.load({
    		callback:function(){
    			//关闭容器的等待提示
    			Ext.getCmp('pivotgridContainer').el.unmask();
			}
        });
        //var end = new Date().getTime();
		//alert("收集数据:" + (end-start)/1000 + "seconds");
	}
	
	//显示保存窗体
	function prepareSave(){
		if(Ext.getCmp('presavewin') == null)
        new Ext.Window({
            title		:'保存报表',
            id:'presavewin',
            layout      : 'fit',
            width       : 350,
            height      : 300,
            closeAction :'hide',
            plain       : true,
            resizable	: false ,
            buttonAlign :'center',
			contentEl   :'presaveDiv',
			modal:true,
			buttons: [
			{
            	text: '确定',
            	handler:function(button, event)
            	{
            		var reportName = Ext.getDom("report_name").value;
            		var reportType = Ext.getDom("report_type").value;
            		var path = Ext.getDom("saveReportSummaryLocation").value;
            		var description = Ext.getDom("report_description").value;
            		if(reportName == ""||reportName == null)
            		{
            			alert("请填写名称");
            			return;
            		}
            		if(path == ""|| path == null)
            		{
            			alert("请选择保存位置");
            			return;
            		}
            		Ext.getCmp('presavewin').hide();
            		save();
            	}
	        },
	        {
	            text: '取消',
	            handler:function(button, event)
	            {
	            	Ext.getCmp('presavewin').hide();
	            }
	        }]
        });
		Ext.getCmp('presavewin').show();
	}
	
	//保存
	function save(){
		/**
		 * 保存交叉报表
		 */
		//打开遮罩层
		Ext.MessageBox.show({
	           msg: '正在保存，请稍候...',
	           width:300,
	           closable :true,
	           icon:'saving',
	           progress:true,
	           animEl: 'mb7'
	    });
		//进度条控制
		var progressEnd = false;
		var f = function(v){
            return function(){
            	var i = v/11;
            	if(v > 11){
            	}else if(v == 11 && !progressEnd){
                	Ext.MessageBox.updateProgress(i, '99% 已完成');
                }else if(!progressEnd){
                    Ext.MessageBox.updateProgress(i, Math.round(100*i)+'% 已完成');
                }
           };
        };
        for(var i = 1; i < 13; i++){
           setTimeout(f(i), i*500);
        }
		//套表id
		var xmlId = xml_id_;
		//处理指标栏保存内容
		var measureContent = [];
		Ext.getCmp('measures_grid').getStore().each(
				function(record){
					measureContent.push(record.data);
				}
		);
		//处理宾栏保存内容
		var colContent = [];
		Ext.getCmp('binlan').root.eachChild(function(node){
			var group = node.attributes;
			group.children = [];
			node.eachChild(function(node_){
				group.children.push({tree:node_.attributes.tree,table:node_.attributes.table,val:node_.attributes.val,isCopy:true,group:node_.attributes.group,leaf:true});
			});
			colContent.push(group);
		});
		//处理主栏保存内容
		var rowContent = [];
		Ext.getCmp('zhulan').root.eachChild(function(node){
			var group = node.attributes;
			group.children = [];
			node.eachChild(function(node_){
				group.children.push({tree:node_.attributes.tree,table:node_.attributes.table,val:node_.attributes.val,isCopy:true,group:node_.attributes.group,leaf:true});
			});
			rowContent.push(group);
		});
		//是否开启总计
		var isSum = Ext.getCmp('isSum').isSum;
		//是否开启钻取
		var isDrillDown = Ext.getCmp('isDrillDown').isDrillDown;
		//报表名称
		var reportName = Ext.getDom('report_name').value;
		//报表类型
		var reportType = Ext.getDom('report_type').value;
		//资源保存位置
		var repository_id = Ext.getDom('repository_id').value;
		//描述信息
		var description = Ext.getDom('report_description').value;
		//制作人
		var author = 'admin';
		//全局条件
		var conditions = '';
		if(Ext.getCmp('conditions_grid_')){
			Ext.getCmp('conditions_grid_').getStore().each(function(record){
				conditions += ' ' + record.data.join + ' ' + record.data.code;
			});
		}
		//发起ajax保存
		Ext.Ajax.request({
			   timeout:9999999,
	 		   method: "post",
	 		   url:'${pageContext.request.contextPath}}/operateCrossReport.report?method=saveOrUpdate&decorate=no',
	 		   params: {
					xmlId:xmlId,
					measureContent:Ext.encode(measureContent),
					colContent:Ext.encode(colContent),
					rowContent:Ext.encode(rowContent),
					isSum:isSum,
					isDrillDown:isDrillDown,
					reportName:reportName,
					reportType:reportType,
					repository_id:repository_id,
					description:description,
					author:author,
					conditions:conditions,
					reportId:reportId
			   },
	 		   success: function(msg){
				   if(msg.responseText == 'success'){
					   progressEnd = true;//停止更新进度条,直接设置为100%
					   Ext.MessageBox.updateProgress(1, '100% 保存成功');
					   setTimeout(function(){
						   Ext.MessageBox.hide();
					   },1000);
				   }else{
					   Ext.MessageBox.show({
						   title: '提示',
						   msg: '保存失败!',
						   buttons: Ext.MessageBox.OK,
						   animEl: 'mb9',
						   icon: Ext.MessageBox.ERROR
					   });
				   }
	 		   }
		});
		
	}
	
	//保存时选择保存位置用
	function getType(){
		if(Ext.getCmp('repository') == null){
	    	new Ext.Window({
	    		id:'repository',
			  	title:"资源管理器目录",
		        width: 450,
		        height:350,
		        layout:'fit',
		        buttonAlign:'center',
		        resizable:false,
		        closeAction :'hide',
		        modal:true,
		        items: [{
					id:'repositorytree',
			        useArrows: true,
			        autoScroll: true,
			        border: false,
			        xtype:'treepanel',
			        loader: new Ext.tree.TreeLoader({ 
			        		dataUrl: '${pageContext.request.contextPath}/treeQuery.tree?method=queryNode&key=repositoryTreeAdapter',
			        		listeners:{beforeload:function(treeLoader, node) {
						        this.baseParams.id = node.id;
						    }}
					  }),
			        root: {
			            nodeType: 'async',
			            text: '资源管理器目录',
			            draggable: false,
			            id: '-1'
			        },
			        listeners:{dblclick:function(n,e){
							Ext.getDom("repository_id").value=n.id;
							Ext.getDom("saveReportSummaryLocation").value=n.text;
							Ext.getCmp('repository').hide();
						}
			        }
			    }]
	    	 });
		}
		Ext.getCmp('repositorytree').expandAll();
	    Ext.getCmp('repository').show();
 	}
	
	function getRootPath(){
			return Constant_System_BasePath;
	}
	
	//计算别名长度考虑中文占2位
	function getLen(str) { 
		var odds = 0; 
		for (var i=0;i <str.length;i++){ 
			if(str.charCodeAt(i) > 255)
				odds++; 
		} 
		return   (str.length   +   odds); 
	}  
	
	function writeCondition(text){
		var tc = Ext.getDom("selColumnCondition_simple_conditions_");
	    var tclen = tc.value.length;
	    tc.focus();
	    if(typeof document.selection != "undefined")
	    {
	        document.selection.createRange().text = text;  
	    }
	    else
	    {
	        tc.setValue(tc.value.substr(0,tc.selectionStart)+text+tc.value.substring(tc.selectionStart,tclen));
	    }
	}

	function addquery(o,sqlTextareaId,column){
	    var tc = Ext.getDom(sqlTextareaId);
	    var tclen = tc.value.length;
	    tc.focus();
	    var str=o.text;
	    if(column)
	    	str+="("+column+")";
	    if(typeof document.selection != "undefined")
	    {
	        document.selection.createRange().text = str;  
	    }
	    else
	    {
	        tc.setValue(tc.value.substr(0,tc.selectionStart)+str+tc.value.substring(tc.selectionStart,tclen));
	    }
	}
	
	//固定报告期年下拉列表
 	function getYear(yearId){
 		var year=new Date().format("Y");
 		var yearArray = new Array(); 
 		for(var i=0;i<21;i++){
				yearArray[i]=new Array();
				yearArray[i][0]=(parseInt(year)+i-15)+"年";
				yearArray[i][1]=(parseInt(year)+i-15);
 		}
 		var com_ds_year = new Ext.data.SimpleStore({    
 			fields:["name","valtext"],   
 			data:yearArray  
 		});   
 		var comboBox_year = new Ext.form.ComboBox({
 			id:yearId,
 			width:100,
 			selectOnFocus : true,	 
 			fieldLabel:'维表报告期',	
 			editable:false,
 			store:com_ds_year,
 			triggerAction: "all",  //不加该语句选中某项后
 			mode: "local",   //动态需要	
 			displayField: "name",
 			valueField: "valtext",
 			value:yearArray[14][1]
 			});	
			return comboBox_year;		
 	}
 	

 	function reportTime(){
		//报告期
		var fields=["valtext","name"];
		var data_report=[['01','去年同期'],['02','上一期'],['03','前N期']];
		var store_report = new Ext.data.SimpleStore({ 
			fields:fields,
			data:data_report
		});

		var comboBox_report = new Ext.form.ComboBox({
			id:'comboBox_reportId',
			width: 210, 
			selectOnFocus : true,	 
			editable:false,
			fieldLabel:'相对报告期',	
			store:store_report,
			triggerAction: "all",  //不加该语句选中某项后
			mode: "local",   //动态需要	
			displayField: "name",
			valueField: "valtext",
			value:'03',
			listeners: {
				"select": function (combo,record,index){ 
					switch(record.get("valtext")){
						case "03":Ext.getCmp("timeCustom").enable();Ext.getCmp("timeCustom").show(); Ext.getCmp("timeCustom").getEl().up('.x-form-item').setDisplayed(true);break;
						default: Ext.getCmp("timeCustom").disable();Ext.getCmp("timeCustom").hide();Ext.getCmp("timeCustom").getEl().up('.x-form-item').setDisplayed(false);
					}
				 }
			}	   		
		});	
		return comboBox_report;
 	}
 	
	//验证全数字
 	function isDigit(s) 
 	{ 
	 	var patrn=/^[0-9]{1,20}$/; 
	 	if (!patrn.exec(s))return false;
	 	return true; 
 	} 


 	//固定报告期季度下拉列表
 	function getSeason(data_season){
 		data_season = data_season || {};
	 	var fields=["valtext","name"];
//	 	var data_season=[['03','第一季度'],['06','第二季度'],['09','第三季度'],['12','第四季度']];
	 	var store_season = new Ext.data.SimpleStore({ 
	 		fields:fields,
	 		data:data_season
	 	});
	 	var comboBox_season = new Ext.form.ComboBox({
	 		id:'seasonId',
	 		anchor:"83%",
	 		selectOnFocus : true,	 
	 		allowBlank:false,
	 		editable:false,
	 		fieldLabel:'选择季度',	
	 		store:store_season,
	 		triggerAction: "all",  //不加该语句选中某项后
	 		mode: "local",   //动态需要	
	 		displayField: "name",
	 		valueField: "valtext",
	 		value:'12',
	 		listeners: {
	 			"select": function (combo,record,index){ 
	 				//record.get("name");
	 			 }
	 		}	   		
	 	});	
	 	return comboBox_season;		
 	}
 	//选完报告期后刷新树结点
 	function refreshNode(tree_id,id){
 		if(Ext.getCmp('customH_win_') && Ext.getCmp('customH_win_').isVisible())
	 		tree_id = "tree-panel-measures";
 		else if(Ext.getCmp('customH_win_modify_') && Ext.getCmp('customH_win_modify_').isVisible())
	 		tree_id = "tree-panel-measures-modify";
 		else if(Ext.getCmp('customH_win_conditions_') && Ext.getCmp('customH_win_conditions_').isVisible()){
 			tree_id = "tree-panel-conditions";
 		}
 		Ext.getCmp(tree_id).getNodeById(id).reload();
 	}
 	//选择报告期
 	function selectTime(o,id,type,tree_id){
 		if(Ext.getCmp('customH_win_') && Ext.getCmp('customH_win_').isVisible())
	 		tree_id = "tree-panel-measures";
 		else if(Ext.getCmp('customH_win_modify_') && Ext.getCmp('customH_win_modify_').isVisible())
	 		tree_id = "tree-panel-measures-modify";
 		else if(Ext.getCmp('customH_win_conditions_') && Ext.getCmp('customH_win_conditions_').isVisible()){
 			tree_id = "tree-panel-conditions";
 		}
	 	var type_name;
	 	var data_season;
	 	switch(type){
	 		case 1:
	 			type_name = '年报';
		 		break;
	 		case 3:
	 			type_name = '月报';
		 		break;
	 		case 4:
	 			type_name = '季报3';
	 			data_season=[['03','第一季度'],['06','第二季度'],['09','第三季度'],['12','第四季度']];
		 		break;
	 		case 401:
	 			type_name = '季报1';
	 			data_season=[['01','第一季度'],['04','第二季度'],['07','第三季度'],['10','第四季度']];
		 		break;
	 		case 402:
	 			type_name = '季报2';
	 			data_season=[['02','第一季度'],['05','第二季度'],['08','第三季度'],['11','第四季度']];
		 		break;
	 		case 403:
	 			type_name = '季报3';
	 			data_season=[['03','第一季度'],['06','第二季度'],['09','第三季度'],['12','第四季度']];
		 		break;			 					 					 		
	 		case 8:
	 			type_name = '维表';
	 			break;
	 		case 9:
	 			type_name = '随机报';
		 		break;
	 	}
//	 	if(Ext.getCmp('customH_win_') && Ext.getCmp('customH_win_').isVisible()){
//	 		tree_id = "tree-panel-measures"
//	 	}
	    //客户选择时间操作
	    if(Ext.getCmp('timeSelectWin_') == null){
	    	var node = Ext.getCmp(tree_id).getNodeById(id);
	    	var node_tableCode_ = node.attributes.table.replace(new RegExp("\\[.*\\]","gm"),"");
	    	var tablestr="";
	    	if(node.attributes.d=='v'){ //维表不查后台
		 		timeSelectWin = new Ext.Window({
			 		id:'timeSelectWin_',
				  	title:"请选择报告期:<b>["+Ext.getCmp(tree_id).getNodeById(id).attributes.label+"]</b>",
			        width: 450,
			        height:240,
			        plain:true,
			        layout:'form',
			        buttonAlign:'center',
			        bodyStyle:'padding:5px 5px 5px 5px',
			        resizable:false,
			        buttons: [{
			            text: '保存',
			            handler:function(){
			        			var node = Ext.getCmp(tree_id).getNodeById(id);
			            	if(Ext.getCmp('fixset').collapsed == false){
			            		if(!Ext.getCmp('timeFix').validate())
					            	return;
			            		var time;
						        	if(type=='1'||type=='8'){
							        	time = Ext.getCmp("yearId").getValue();
							      }
							 		else if(type=='3'){
								 		time = Ext.getCmp('timeFix').getRawValue();
								 	}
							 		else{
								 		time = Ext.getCmp("yearId").getValue()+Ext.getCmp("seasonId").getValue();
								 	}
								 	o.innerText=time;
								 	node.attributes.time=time;
								 	node.attributes.table=node.attributes.table.replace(new RegExp("\\[.*\\]","gm"),"[year_fix#"+time+"]");
			            	}
			            	else if(Ext.getCmp('currentset').collapsed == false){
								 	o.innerText="当前期";
								 	node.attributes.time="当前期";
								 	node.attributes.table=node.attributes.table.replace(new RegExp("\\[.*\\]","gm"),"[year]");
			            	}
			            	else{
			            		if(!Ext.getCmp('timeCustom').validate())
					            	return;
			            		var reportType = Ext.getCmp('comboBox_reportId').getValue();
			            		var number = Ext.getCmp('timeCustom').getValue();
									switch(reportType){
									case "01":o.innerText='去年同期';node.attributes.time='去年同期';node.attributes.table=node.attributes.table.replace(new RegExp("\\[.*\\]","gm"),"[year_last]");break;
									case "02":o.innerText='上一期';node.attributes.time='上一期';node.attributes.table=node.attributes.table.replace(new RegExp("\\[.*\\]","gm"),"[year#01]");break;
									default: o.innerText='前'+number+'期';node.attributes.time='前'+number+'期';node.attributes.table=node.attributes.table.replace(new RegExp("\\[.*\\]","gm"),"[year#"+number+"]"); 
									}
			            	}
							 	node.reload();
							 	timeSelectWin.close();
			            }
			        },{
			            text: '取消',
			            handler:function(){
			        		timeSelectWin.close();
			            }
			        }],
			        items: [{
				        labelWidth: 75, 
				        frame:true,
				        bodyStyle:'padding:5px 5px 5px 5px',
				        //width: 430,
				        //height:240,
				        items: [{
					        id:'currentset',
				            xtype:'fieldset',
				            checkboxToggle:true,
				            title: '当前期',
				            autoHeight:true,
				            collapsed:!(o.innerText=='当前期'),
				            defaults: {width: 210},
				            defaultType: 'textfield',
				            items :[
									new Ext.form.TextField({fieldLabel:'报表类型',value:type_name,readOnly:true}),
									new Ext.form.TextField({id:'timeWeiBiaoId',fieldLabel:'当前报告期',value:Ext.getCmp('currentTime').getRawValue(),readOnly:true})
					        ],
				            listeners:{'expand':function(p){
					            Ext.getCmp('fixset').collapse();
					            Ext.getCmp('relativeset').collapse();
					        }}
				        },{
					        id:'fixset',
				            xtype:'fieldset',
				            checkboxToggle:true,
				            title: '固定报告期',
				            autoHeight:true,
				            collapsed:!(isDigit(o.innerText)),
				            defaults: {width: 350},
				            items :[{
									layout:'form',
									defaults:{layout:'form'},
									items:[{
												fieldLabel:'报表类型',
												xtype:'textfield',
												value:type_name,readOnly:true
											},{
												id:'timeFixOut',
												items:[{id:'timeFix',xtype:'datefield',allowBlank:false,fieldLabel:'固定报告期',format:'Ym',value:o.innerText,initDate : '201105',initDateFormat: 'Ym'}]
											},{
												id:'yearIdOut',
												items:[getYear("yearId")]
											},{
												id:'seasonIdOut',
												items:[getSeason(data_season)]
											}
									]
			            	}],
				            listeners:{'expand':function(p){
					            Ext.getCmp('currentset').collapse();
					            Ext.getCmp('relativeset').collapse();
					        }}
				        },{
					        id:'relativeset',
				            xtype:'fieldset',
				            checkboxToggle:true,
				            title: '相对报告期',
				            autoHeight:true,
				            collapsed:!(o.innerText!='当前期'&&(!isDigit(o.innerText))),
				            defaults: {width: 350},
				            items :[
									new Ext.FormPanel({
										items:[{fieldLabel:'报表类型',xtype:'textfield',value:type_name,width:210,readOnly:true},
										       reportTime(),
										       new Ext.form.TextField({id:'timeCustom',allowBlank:false,fieldLabel:'前N期',xtype:'textfield',value:'3'})
										]
									})
				            ],
				            listeners:{'expand':function(p){
					            Ext.getCmp('currentset').collapse();
					            Ext.getCmp('fixset').collapse();
					        }}
				        }]
		 		}]
		    	 });
		 		timeSelectWin.show();
	        	if(type=='1'){
	        		Ext.getCmp("timeFix").disable();Ext.getCmp("timeFixOut").hide();
	        		Ext.getCmp("seasonId").disable();Ext.getCmp("seasonIdOut").hide();
	        		Ext.getCmp("yearId").enable();Ext.getCmp("yearIdOut").show();
		 		 }
		 		 else if(type=='3'){
		 			Ext.getCmp("yearId").disable();Ext.getCmp("yearIdOut").hide();
		 			Ext.getCmp("seasonId").disable();Ext.getCmp("seasonIdOut").hide();
		 			Ext.getCmp("timeFix").enable();Ext.getCmp("timeFixOut").show();
		 		 }
		 		 else if(type=='8'){
		 			Ext.getCmp("timeWeiBiaoId").setValue(Ext.getCmp("currentTimeWeiBiao").getValue());//设置当前期
		 			Ext.getCmp("yearId").enable();Ext.getCmp("yearIdOut").show();
		 			Ext.getCmp("seasonId").disable();Ext.getCmp("seasonIdOut").hide();
		 			Ext.getCmp("timeFix").disable();Ext.getCmp("timeFixOut").hide();
		 			Ext.getCmp("relativeset").hide();//隐藏相对报告期
			 	 }
		 		 else{
		 			Ext.getCmp("timeFix").disable();Ext.getCmp("timeFixOut").hide();
		 			Ext.getCmp("yearId").enable();Ext.getCmp("yearIdOut").show();
		 			Ext.getCmp("seasonId").enable();Ext.getCmp("seasonIdOut").show();
		 		 }
	    	}
	    	else{//事实表查后台
	    		Ext.Ajax.request({
			 		   method: "post",
			 		   url:'${pageContext.request.contextPath}/importData.report?method=getTableImf',
			 		   params: {date:new Date(),code:node_tableCode_},
			 		   success: function(msg){
			 			   var str=eval(msg.responseText);
			 			   for(var i=0;i<str.length;i++){
			 			   	tablestr+=str[i]+"\r\n";
			 			   }
					 		timeSelectWin = new Ext.Window({
						 		id:'timeSelectWin_',
							  	title:"请选择报告期:<b>["+Ext.getCmp(tree_id).getNodeById(id).attributes.label+"]</b>",
						        width: 450,
						        height:430,
						        plain:true,
						        layout:'form',
						        buttonAlign:'center',
						        bodyStyle:'padding:5px 5px 5px',
						        resizable:false,
						        buttons: [{
						            text: '保存',
						            handler:function(){
						        			var node = Ext.getCmp(tree_id).getNodeById(id);
						            	if(Ext.getCmp('fixset').collapsed == false){
						            		if(!Ext.getCmp('timeFix').validate())
								            	return;
						            		var time;
									        	if(type=='1'||type=='8'){
										        	time = Ext.getCmp("yearId").getValue();
										      }
										 		else if(type=='3'){
											 		time = Ext.getCmp('timeFix').getRawValue();
											 	}
										 		else{
											 		time = Ext.getCmp("yearId").getValue()+Ext.getCmp("seasonId").getValue();
											 	}
											 	o.innerText=time;
											 	node.attributes.time=time;
											 	node.attributes.table=node.attributes.table.replace(new RegExp("\\[.*\\]","gm"),"[year_fix#"+time+"]");
						            	}
						            	else if(Ext.getCmp('currentset').collapsed == false){
											 	o.innerText="当前期";
											 	node.attributes.time="当前期";
											 	node.attributes.table=node.attributes.table.replace(new RegExp("\\[.*\\]","gm"),"[year]");
						            	}
						            	else{
						            		if(!Ext.getCmp('timeCustom').validate())
								            	return;
						            		var reportType = Ext.getCmp('comboBox_reportId').getValue();
						            		var number = Ext.getCmp('timeCustom').getValue();
												switch(reportType){
												case "01":o.innerText='去年同期';node.attributes.time='去年同期';node.attributes.table=node.attributes.table.replace(new RegExp("\\[.*\\]","gm"),"[year_last]");break;
												case "02":o.innerText='上一期';node.attributes.time='上一期';node.attributes.table=node.attributes.table.replace(new RegExp("\\[.*\\]","gm"),"[year#01]");break;
												default: o.innerText='前'+number+'期';node.attributes.time='前'+number+'期';node.attributes.table=node.attributes.table.replace(new RegExp("\\[.*\\]","gm"),"[year#"+number+"]"); 
												}
						            	}
										 	node.reload();
										 	timeSelectWin.close();
						            }
						        },{
						            text: '取消',
						            handler:function(){
						        		timeSelectWin.close();
						            }
						        }],
						        items: [{
							        labelWidth: 75, 
							        frame:true,
							        bodyStyle:'padding:5px 5px 5px',
							        //width: 230,
							        height:340,
							        items: [{
								        id:'currentset',
							            xtype:'fieldset',
							            checkboxToggle:true,
							            title: '当前期',
							            autoHeight:true,
							            collapsed:!(o.innerText=='当前期'),
							            defaults: {width: 210},
							            defaultType: 'textfield',
							            items :[
												new Ext.form.TextField({fieldLabel:'报表类型',value:type_name,readOnly:true}),
												new Ext.form.TextField({id:'timeWeiBiaoId',fieldLabel:'当前报告期',value:Ext.getCmp('currentTime').getRawValue(),readOnly:true})
								        ],
							            listeners:{'expand':function(p){
								            Ext.getCmp('fixset').collapse();
								            Ext.getCmp('relativeset').collapse();
								        }}
							        },{
								        id:'fixset',
							            xtype:'fieldset',
							            checkboxToggle:true,
							            title: '固定报告期',
							            autoHeight:true,
							            collapsed:!(isDigit(o.innerText)),
							            defaults: {width: 350},
							            items :[{
												layout:'form',
												defaults:{layout:'form'},
												items:[{
															fieldLabel:'报表类型',
															xtype:'textfield',
															value:type_name,readOnly:true
														},{
															id:'timeFixOut',
															items:[{id:'timeFix',width:100,xtype:'datefield',allowBlank:false,fieldLabel:'固定报告期',format:'Ym',value:o.innerText,initDate : '201105',initDateFormat: 'Ym'}]
														},{
															id:'yearIdOut',
															items:[getYear("yearId")]
														},{
															id:'seasonIdOut',
															items:[getSeason(data_season)]
														}
												]
						            	}],
							            listeners:{'expand':function(p){
								            Ext.getCmp('currentset').collapse();
								            Ext.getCmp('relativeset').collapse();
								        }}
							        },{
								        id:'relativeset',
							            xtype:'fieldset',
							            checkboxToggle:true,
							            title: '相对报告期',
							            autoHeight:true,
							            collapsed:!(o.innerText!='当前期'&&(!isDigit(o.innerText))),
							            defaults: {width: 350},
							            items :[
												new Ext.FormPanel({
													items:[{fieldLabel:'报表类型',xtype:'textfield',value:type_name,width:210,readOnly:true},
													       reportTime(),
													       new Ext.form.TextField({id:'timeCustom',allowBlank:false,fieldLabel:'前N期',xtype:'textfield',value:'3'})
													]
												})
							            ],
							            listeners:{'expand':function(p){
								            Ext.getCmp('currentset').collapse();
								            Ext.getCmp('fixset').collapse();
								        }}
							        },{
								        id:'table_code',
							            xtype:'fieldset',
							            title: node.attributes.label,
							            autoHeight:true,
							            items :[{
											  	xtype:'textarea',
											  	width:"100%",
											  	hideLabel:true,
											  	value:tablestr
											  }
							            ]
								       }]
					 		}]
					    	 });
					 		timeSelectWin.show();
				        	if(type=='1'){
				        		Ext.getCmp("timeFix").disable();Ext.getCmp("timeFixOut").hide();
				        		Ext.getCmp("seasonId").disable();Ext.getCmp("seasonIdOut").hide();
				        		Ext.getCmp("yearId").enable();Ext.getCmp("yearIdOut").show();
					 		 }
					 		 else if(type=='3'){
					 			Ext.getCmp("yearId").disable();Ext.getCmp("yearIdOut").hide();
					 			Ext.getCmp("seasonId").disable();Ext.getCmp("seasonIdOut").hide();
					 			Ext.getCmp("timeFix").enable();Ext.getCmp("timeFixOut").show();
					 		 }
					 		 else if(type=='8'){
					 			Ext.getCmp("timeWeiBiaoId").setValue(Ext.getCmp("currentTimeWeiBiao").getValue());//设置当前期
					 			Ext.getCmp("yearId").enable();Ext.getCmp("yearIdOut").show();
					 			Ext.getCmp("seasonId").disable();Ext.getCmp("seasonIdOut").hide();
					 			Ext.getCmp("timeFix").disable();Ext.getCmp("timeFixOut").hide();
					 			Ext.getCmp("relativeset").hide();//隐藏相对报告期
						 	 }
					 		 else{
					 			Ext.getCmp("timeFix").disable();Ext.getCmp("timeFixOut").hide();
					 			Ext.getCmp("yearId").enable();Ext.getCmp("yearIdOut").show();
					 			Ext.getCmp("seasonId").enable();Ext.getCmp("seasonIdOut").show();
					 		 }
			 		   }
			 		})
	    	}
	    }
	}
 	function afterLoadingMaskFadeOut(){
		//页面切换结束回调
	}
 	//编辑宾栏主栏
 	function editNode(treeid,nodeid){
 		var node = Ext.getCmp(treeid).getNodeById(nodeid);
 		alert(node.attributes.table + '.' + node.attributes.val);
 	}
 	//清空子结点
 	function cleanNodes(treeid,nodeid){
 		var node = Ext.getCmp(treeid).getNodeById(nodeid);
 		while(node.hasChildNodes()){
 			node.item(0).remove();
 		}
 	}
 	
 	/**
 	 * 宾栏和主栏拖拽树时选择层次
 	 */
//拖拽树选择深度
   function findTreeNode(node,target){
		var fields=["valtext","name"];
		var data_combo=[['1','1层'],['2','2层'],['3','3层']];
		var store_combo = new Ext.data.SimpleStore({ 
			fields:fields,
			data:data_combo
		});
		var comboBox_combo = new Ext.form.ComboBox({
			id:'comboBox_comboId',
			anchor:'100%', 
			selectOnFocus : true,	 
			allowBlank:false,
			editable:false,
			emptyText: '请选择查询层数', 
			fieldLabel:'查询层数',	
			store:store_combo,
			triggerAction: "all",  
			mode: "local",  
			displayField: "name",
			valueField: "valtext",
			value:'1'
		});		
		var win = new Ext.Window({
			id:'nodeLevelId',
			width: 300,
			height:115,
			layout: 'fit',
			modal:true,
			closeAction:'close',
			buttonAlign:'center',
			resizable:true,
			items: [{
				layout:'form',	
				frame:true,
				items:[comboBox_combo],
				buttons:[{
					text:'确定',
					xtype:'button',
					handler:function(){
							Ext.Ajax.request({
								url:'${pageContext.request.contextPath}/summaryReport.report?method=findTreeNode',
								method:'post',
								params:{
									nodeId:node.attributes.val,
									tableName:node.attributes.table,
									depth:Ext.getCmp('comboBox_comboId').getValue(),
									currentTime:Ext.getCmp("currentTimeWeiBiao").getValue(),
								    type:'8'
								}, // 以json格式传值给后台的
								success: function(response,options){
									if(node.attributes.val!='-1'){
										addNode(Ext.apply({isCopy:true,leaf:true},node.attributes),target);
									}
									var responseArray = Ext.util.JSON.decode(response.responseText);
									for(var i=0;i<responseArray.length;i++){
										var config = Ext.applyIf({isCopy:true,leaf:true,group:responseArray[i].NAME,val:responseArray[i].ID},node.attributes);
										addNode(config,target);
									}
							 	}
							});//submit
						 win.close();
					}
			    }]
			}
			]
		});	
		win.show();
   }
   //添加节点
   function addNode(config,target){
		delete config.id; //剔除id属性
		var copy = new Ext.tree.TreeNode(
				config
		);
		if(target.attributes.isDir == true){ //是拖到分组根目录上
			target.appendChild(copy);
		}else{ //是拖到分组子项,需要做插入操作
			target.parentNode.insertBefore(copy,target);
		}
   }

